package com.ml.doctor.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ml.doctor.R;
import com.ml.doctor.bean.BsBean;
import com.ml.doctor.bean.PatientBean;
import com.ml.doctor.bean.XXBean;
import com.ml.doctor.call2.NimCallActivity;
import com.ml.doctor.call2.QianZui;
import com.ml.doctor.view.CycleImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PatientDetailActivity extends BaseActivity {
    PatientBean patientBean;
    @BindView(R.id.iv_avatar)
    CycleImageView ivAvatar;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.txt_sex)
    TextView txtSex;
    @BindView(R.id.txt_age)
    TextView txtAge;
    @BindView(R.id.iv_phone)
    TextView ivPhone;
    @BindView(R.id.txt_bs)
    TextView txtBs;
    @BindView(R.id.iv_xx)
    TextView ivXx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patient_detail_layout);
        ButterKnife.bind(this);
        setTopTitle("患者详情");
        getData();
    }

    private void getData() {
        patientBean = getSerializableParam("patient", PatientBean.class);
        setUpView();
    }

    private void setUpView() {
        String xx = "";
        Glide.with(this).load(patientBean.user_photo).asBitmap().into(ivAvatar);
        txtName.setText(patientBean.bname);
        txtAge.setText(patientBean.age + "岁");
        txtSex.setText(patientBean.sex);
        ivPhone.setText("联系方式：" + patientBean.tel);
        txtBs.setText("病        史：" + patientBean.mh);
        if (!TextUtils.isEmpty(patientBean.eating_habits)) {
            xx += XXBean.eat[Integer.parseInt(patientBean.eating_habits) - 1];
        }
        if (!TextUtils.isEmpty(patientBean.smoke)) {
            xx += "," + XXBean.smoke[Integer.parseInt(patientBean.smoke) - 1];
        }
        if (!TextUtils.isEmpty(patientBean.drink)) {
            xx += "," + XXBean.drink[Integer.parseInt(patientBean.drink) - 1];
        }
        if (!TextUtils.isEmpty(patientBean.exercise_habits)) {
            xx += "," + XXBean.sport[Integer.parseInt(patientBean.exercise_habits) - 1];
        }
        ivXx.setText(xx);
        try {
            if (!TextUtils.isEmpty(patientBean.mh) && !patientBean.mh.equals("尚未填写") && !patientBean.mh.equals("11")) {
                String arr[] = patientBean.mh.split(",");
                String mh = "";
                for (int i = 0; i < arr.length; i++) {
                    mh += BsBean.BS[Integer.parseInt(arr[i]) - 1] + ",";
                }
                if (!TextUtils.isEmpty(mh)) {
                    mh = mh.substring(0, mh.length() - 1);
                }
                txtBs.setText("病        史：" + mh);
            } else {
                txtBs.setText("病        史：尚未填写");
            }
        } catch (Exception e) {

        }

    }

    @OnClick({R.id.iv_yz, R.id.iv_call, R.id.bi_twjl, R.id.bi_xyajl,
            R.id.bi_xyangjl, R.id.bi_xtl, R.id.bi_xljl, R.id.bi_mbjl, R.id.bi_dgcjl, R.id.bi_nsjl, R.id.bi_xd})
    public void onClick(View view) {
        Intent i = new Intent(PatientDetailActivity.this, ChatActivity.class);
        switch (view.getId()) {
            case R.id.iv_yz:
                break;
            case R.id.iv_call:
                NimCallActivity.launch(this, QianZui.qianZui + patientBean.bid);
//                NimCallActivity.launch(this, "100001");
                break;
            case R.id.bi_twjl:
                i.putExtra("temp", 1);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_xyajl:
                i.putExtra("temp", 2);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_xyangjl:
                i.putExtra("temp", 5);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_xtl:
                i.putExtra("temp", 4);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_xljl:
                i.putExtra("temp", 3);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_mbjl:
                i.putExtra("temp", 6);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_dgcjl:
                i.putExtra("temp", 7);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_nsjl:
                i.putExtra("temp", 8);
                i.putExtra("bid", patientBean.bid);
                startActivity(i);
                break;
            case R.id.bi_xd:
                Intent i1 = new Intent(this, XDActivity.class);
                i1.putExtra("bid", patientBean.bid);
                startActivity(i1);
                break;

        }
    }


}
